package com.huizu.project.apiController;

import com.huizu.common.annotation.Anonymous;
import com.huizu.common.annotation.Log;
import com.huizu.common.core.controller.BaseController;
import com.huizu.common.core.domain.AjaxResult;
import com.huizu.common.core.page.TableDataInfo;
import com.huizu.common.enums.BusinessType;
import com.huizu.common.utils.poi.ExcelUtil;
import com.huizu.project.domain.ProSp;
import com.huizu.project.domain.ProSpPraise;
import com.huizu.project.domain.ProSpReview;
import com.huizu.project.service.IProSpService;
import com.huizu.project.utils.TokenUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 视频管理Controller
 * 
 * @author zhangmx
 * @date 2024-06-05
 */
@Anonymous
@RestController
@RequestMapping("/api/prosp")
public class ApiProSpController extends BaseController
{
    @Autowired
    private IProSpService proSpService;

    /**
     * 查询视频管理列表
     */
    @PostMapping("/list")
    public TableDataInfo list(@RequestBody ProSp proSp)
    {
        List<ProSp> list = proSpService.selectProSpList(proSp);
        return getDataTable(list);
    }

    /**
     * 获取视频管理详细信息
     */
    @PostMapping(value = "/getById")
    public AjaxResult getInfo(@RequestBody ProSp proSp)
    {
        String id = proSp.getId();
        return success(proSpService.selectProSpById(id));
    }

    /**
     * 新增视频管理
     */
    @PostMapping("/add")
    public AjaxResult add(@RequestBody ProSp proSp, HttpServletRequest request)
    {
        String token = request.getHeader(TokenUtils.getAppTokenHeader());
        String userId = TokenUtils.parseToken(token);//获取用户id
        proSp.setUserId(userId);
        return toAjax(proSpService.insertProSpApi(proSp));
    }

    /**
     * 修改视频管理
     */
    @PostMapping("/update")
    public AjaxResult edit(@RequestBody ProSp proSp)
    {
        return toAjax(proSpService.updateProSp(proSp));
    }

    /**
     * 删除视频管理
     */
	@PostMapping("/delete")
    public AjaxResult remove(@RequestBody String[] ids)
    {
        return toAjax(proSpService.deleteProSpByIds(ids));
    }

    @PostMapping("/review")
    public AjaxResult review(@RequestBody ProSpReview proSpReview,HttpServletRequest request){
        String token = request.getHeader(TokenUtils.getAppTokenHeader());
        String userId = TokenUtils.parseToken(token);//获取用户id
        proSpReview.setUserId(userId);
	    return proSpService.review(proSpReview);
    }

    @PostMapping("/listReview")
    public TableDataInfo listReview(@RequestBody ProSpReview proSpReview){
	    return getDataTable(proSpService.listReview(proSpReview));
    }

    @PostMapping("/updatePraise")
    public AjaxResult updatePraise(@RequestBody ProSpPraise proSpPraise, HttpServletRequest request){
        String token = request.getHeader(TokenUtils.getAppTokenHeader());
        String userId = TokenUtils.parseToken(token);//获取用户id
        proSpPraise.setUserId(userId);
        return proSpService.updatePraise(proSpPraise);
    }

    @PostMapping("/listPraise")
    public TableDataInfo listPraise(@RequestBody ProSpPraise proSpPraise,HttpServletRequest request){
        String token = request.getHeader(TokenUtils.getAppTokenHeader());
        String userId = TokenUtils.parseToken(token);//获取用户id
        proSpPraise.setUserId(userId);
        return getDataTable(proSpService.listPraise(proSpPraise));
    }

}
